#ifndef TEXTEDIT_H
#define TEXTEDIT_H

#include <QPlainTextEdit>
#include <QCompleter>
#include <QAbstractItemView>
#include <QScrollBar>
#include <QPainter>
#include <QTextBlock>
#include <QTextDocumentFragment>

class LineNumber;

class TextEdit : public QPlainTextEdit
{
    Q_OBJECT

    public:
        TextEdit(QFont font, QWidget *parent = 0);
        ~TextEdit();

        void setCompleter(QCompleter *c);
        QCompleter *completer() const;
        void lineNumberAreaPaintEvent(QPaintEvent *event);
        int lineNumberAreaWidth();
        void showLineNumberArea(bool);
        QString textUnderCursor() const;
        void showDocumentation(QString);

    protected:
        void resizeEvent(QResizeEvent *event);
        void keyPressEvent(QKeyEvent *e);
        void focusInEvent(QFocusEvent *e);

    private slots:
        void insertCompletion(const QString &completion);
        void updateLineNumberAreaWidth(int newBlockCount);
        void highlightCurrentLine();
        void updateLineNumberArea(const QRect &, int);

    private:
        QCompleter *c;
        QWidget *lineNumberArea;
        bool manageIndentation();
        void indentSelection(bool);

    signals:
        void documentationReady(QString, QString);
};

#endif // TEXTEDIT_H
